package com.thinkgem.jeesite.common.interceptor;

import com.thinkgem.jeesite.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 文件管理器拦截
 * @author kongxiangsheng
 */
@Slf4j
public class CkfinderInterceepter implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("==========走到了 preHandle() 方法" + "==========");
        HttpSession session = request.getSession();
        String user = (String) session.getAttribute("CKFinder_UserRole");
        if (StringUtils.isNotEmpty(user)) {
            log.info("==========session中的CKFinder_UserRole:" + user + "==========");
            return true;
        }
        log.info("==========session中没有CKFinder_UserRole进行拦截==========");
        return false;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.info("==========走到了 postHandle() 方法");

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.info("==========走到了 afterCompletion() 方法");

    }

}
